package com.xja.service.impl;

import com.xja.common.JsonBean;
import com.xja.entity.SysDept;
import com.xja.mapper.SysDeptMapper;
import com.xja.service.SysDeptService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author CHENCHEN
 * @company 北京学佳澳教育科技
 * @create 2024-01-15 9:53
 */
@Service
public class SysDeptServiceImpl implements SysDeptService {

    @Autowired
    private SysDeptMapper sysDeptMapper;

    @Override
    public JsonBean getTreeList() {
        return new JsonBean(0,"ok",sysDeptMapper.selectTreeList());
    }

    @Override
    public JsonBean selectById(Integer id) {
        return new JsonBean(0,"ok",sysDeptMapper.selectByPrimaryKey(id));
    }

    @Override
    public JsonBean deleteById(Integer id) {
        JsonBean jsonBean = new JsonBean(-1, "fail", null);
        int i = sysDeptMapper.deleteByPrimaryKey(id);
        if(i>0){
            jsonBean = new JsonBean(0, "ok", null);
        }
        return jsonBean;
    }

    @Override
    public JsonBean insertDept(SysDept sysDept) {
        JsonBean jsonBean = new JsonBean(-1, "fail", null);
        int i = sysDeptMapper.insert(sysDept);
        if(i>0){
            jsonBean = new JsonBean(0, "ok", null);
        }
        return jsonBean;
    }

    @Override
    public JsonBean updateDept(SysDept sysDept) {
        JsonBean jsonBean = new JsonBean(-1, "fail", null);
        int i = sysDeptMapper.updateByPrimaryKeySelective(sysDept);
        if(i>0){
            jsonBean = new JsonBean(0, "ok", null);
        }
        return jsonBean;
    }
}
